package com.fr.report.io;

import com.fr.base.core.FT;
import com.fr.base.core.list.IntList;
import com.fr.report.PageSet;
import com.fr.report.PaperSetting;
import com.fr.report.Report;
import com.fr.report.ReportPage;
import com.fr.report.ReportSettings;
import com.fr.report.ResultWorkBook;
import com.fr.report.core.ReportUtils;
import com.fr.report.core.cal.LayerPageReport;
import com.fr.report.core.cal.LayerReport;
import com.fr.report.io.core.PageExcelExporterReport;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.OutputStream;
import java.util.List;

public class PageExcelExporter extends ExcelExporter
{
  public PageExcelExporter(List paramList)
  {
    super(paramList);
  }

  public void export(OutputStream paramOutputStream, ResultWorkBook paramResultWorkBook)
    throws Exception
  {
    export(paramOutputStream, paramResultWorkBook, false);
  }

  public void export(OutputStream paramOutputStream, ResultWorkBook paramResultWorkBook, boolean paramBoolean)
    throws Exception
  {
    if (paramResultWorkBook == null)
      throw new Exception("Report can not be null!");
    for (int i = 0; i < paramResultWorkBook.getReportCount(); ++i)
      if ((paramResultWorkBook.getReport(i) instanceof LayerReport) || (paramResultWorkBook.getReport(i) instanceof LayerPageReport))
      {
        new LargeDataPageExcelExporter(this.paperSettingList, true).export(paramOutputStream, paramResultWorkBook, paramBoolean);
        return;
      }
    super.export(paramOutputStream, paramResultWorkBook, paramBoolean);
  }

  protected void exportBook(ResultWorkBook paramResultWorkBook, HSSFWorkbook paramHSSFWorkbook, List paramList1, List paramList2, List paramList3, boolean paramBoolean)
    throws Exception
  {
    for (int i = 0; i < paramResultWorkBook.getReportCount(); ++i)
    {
      localObject = paramResultWorkBook.getReport(i);
      paramList3.add(localObject);
    }
    PageSet[] arrayOfPageSet = new PageSet[paramResultWorkBook.getReportCount()];
    Object localObject = new int[paramResultWorkBook.getReportCount()];
    int j = 0;
    for (int k = 0; k < paramResultWorkBook.getReportCount(); ++k)
      if (paramResultWorkBook.getReport(k) != null)
      {
        arrayOfPageSet[k] = ((Report)paramList3.get(k)).generateReportPageSet((this.paperSettingList == null) ? null : (PaperSetting)this.paperSettingList.get(k)).getTraversingCase();
        localObject[k] = j;
        j += arrayOfPageSet[k].size();
      }
    for (k = 0; k < paramResultWorkBook.getReportCount(); ++k)
    {
      Report localReport = (Report)paramList3.get(k);
      PageSet localPageSet = arrayOfPageSet[k];
      ReportPage localReportPage = null;
      int l = 0;
      int i1 = 0;
      int i2 = 0;
      int i3 = 0;
      IntList localIntList1 = new IntList();
      localIntList1.add(1);
      IntList localIntList2 = new IntList();
      localIntList2.add(1);
      ReportSettings localReportSettings = ReportUtils.getReportSettings(localReport);
      int i4 = localReportSettings.getPageOrder();
      if (i4 == 0)
      {
        for (i5 = 0; i5 < localPageSet.size(); ++i5)
        {
          localReportPage = localPageSet.getPage(i5);
          if (i1 >= localReportPage.getXY()[1])
            break;
          i1 = localReportPage.getXY()[1];
          i3 += localReportPage.getRowCount();
          if (i3 > ExcelExporter.EXCELROWS)
          {
            localIntList2.add(i1);
            i3 = localReportPage.getRowCount();
          }
        }
        l = localPageSet.size() / i1;
        i5 = 0;
        while (true)
        {
          if (i5 >= localPageSet.size())
            break label584;
          localReportPage = localPageSet.getPage(i5);
          i2 += localReportPage.getColumnCount();
          if (i2 > ExcelExporter.EXCELCOLS)
          {
            localIntList1.add(localReportPage.getXY()[0]);
            i2 = localReportPage.getColumnCount();
          }
          i5 += i1;
        }
      }
      for (int i5 = 0; i5 < localPageSet.size(); ++i5)
      {
        localReportPage = localPageSet.getPage(i5);
        if (l >= localReportPage.getXY()[0])
          break;
        l = localReportPage.getXY()[0];
        i2 += localReportPage.getColumnCount();
        if (i2 > ExcelExporter.EXCELCOLS)
        {
          localIntList1.add(l);
          i2 = localReportPage.getColumnCount();
        }
      }
      i1 = localPageSet.size() / l;
      i5 = 0;
      while (i5 < localPageSet.size())
      {
        localReportPage = localPageSet.getPage(i5);
        i3 += localReportPage.getRowCount();
        if (i3 > ExcelExporter.EXCELROWS)
        {
          localIntList2.add(localReportPage.getXY()[1]);
          i3 = localReportPage.getRowCount();
        }
        i5 += l;
      }
      FT localFT1 = new FT(localObject[k], j);
      int[] arrayOfInt = { l, i1 };
      for (int i6 = 0; i6 < localIntList1.size(); ++i6)
      {
        FT localFT2 = new FT(localIntList1.get(i6), l + 1);
        for (int i7 = 0; i7 < localIntList2.size(); ++i7)
        {
          FT localFT3 = new FT(localIntList2.get(i7), i1 + 1);
          innerExportReport(new PageExcelExporterReport(localReport, localPageSet, localFT2, localFT3, localFT1, arrayOfInt, i4), paramResultWorkBook.getReportExportAttr(), paramResultWorkBook.getReportName(k) + ((i6 == 0) ? "" : new StringBuffer().append("_").append(i6 + 1).toString()) + ((i7 == 0) ? "" : new StringBuffer().append("_").append(i7 + 1).toString()), paramHSSFWorkbook, paramList1, paramList2, k);
        }
      }
      if (!(paramBoolean))
        localPageSet.release();
    }
    label584:
  }
}